package com.aaa.lx1031;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 荆豪峰
 * @version 1.0
 */
public class MyTicket01 implements Runnable{
    private int ticket=100;
    private static Object lock=new Object();
    @Override
    public void run() {
        Lock lock=new ReentrantLock();
        while (true){
          try {
              lock.lock();
              if (ticket >= 0) {
                  System.out.println(Thread.currentThread().getName() + "卖出了一张票"+ticket--);
              }
          }finally {
              lock.unlock();
          }
        }
    }
}
